package service

import (
	"myserver/dao"
	"myserver/model"
	"myserver/param"
	"myserver/tool"
)

type HouseService struct {
}

func (s *HouseService) GetHouse(house model.House) model.House {
	var houseDao = dao.HouseDao{MyOrm: tool.MyDb}
	res := houseDao.GetHouse(&house)
	if res.RowsAffected != 0 {
		return house
	} else {
		return model.House{}
	}
}

func (s *HouseService) CreateHouse(house model.House) int64 {
	var houseDao = dao.HouseDao{MyOrm: tool.MyDb}
	res := houseDao.CreateHouse(house)
	return res
}

func (s *HouseService) DeleteHouse(house model.House) int64 {
	var houseDao = dao.HouseDao{MyOrm: tool.MyDb}
	res := houseDao.DeleteHouse(house)
	return res
}

func (s *HouseService) UpdateHouse(house model.House) int64 {
	var houseDao = dao.HouseDao{MyOrm: tool.MyDb}
	res := houseDao.UpdateHouse(house)
	return res
}

func (s *HouseService) QueryHouses(param param.PageParam) param.ResponsePageParam {
	var houseDao = dao.HouseDao{MyOrm: tool.MyDb}
	res := houseDao.QueryHouses(tool.ToPageParam(param))
	return res
}
